using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using OgilvyOne.IDAL;
using OgilvyOne.Utility;
using OgilvyOne.Model;
namespace OgilvyOne.SqlServerDAL
{
    public class GroupCooprationModule : CommonModule
    {
        // Methods
        private string GetDetailContent(int menuId, int contentId, int pageIndex)
        {
            return base.GetDefaultDetailContent(menuId, contentId);
        }

        private string GetIndexContent(int menuId, int contentId, int pageIndex)
        {
            StringBuilder builder = new StringBuilder();
            string str = string.Empty;
            string str2 = string.Empty;
            MenuDescInfo cacheMenuDesc = new MenuDesc().GetCacheMenuDesc(menuId);
            if (cacheMenuDesc != null)
            {
                str = cacheMenuDesc.Menu_desc;
                str2 = cacheMenuDesc.Menu_title;
            }
            builder.AppendFormat("<div id='contentTitle'>\r\n\t\t\t\t\t{0}\r\n\t\t\t\t</div><!--contentTitle-->\r\n\t\t\t\t\r\n\t\t\t\t<div class='contentText'>\r\n\t\t\t\t\t{1}\r\n\t\t\t\t</div>\r\n\t\t\t\t", str2, str);
            int cnOrEnMenuId = base.sm.GetCnOrEnMenuId("group", menuId);
            IList subMenuList = base.sm.GetSubMenuList(menuId);
            if ((subMenuList != null) && (subMenuList.Count > 0))
            {
                SysMenuInfo info2 = null;
                GroupIndexModule module = new GroupIndexModule();
                int num2 = base.sm.GetCnOrEnMenuId("group_index_id", menuId);
                int num3 = base.sm.GetCnOrEnMenuId("brief_index_id", menuId);
                int num4 = base.sm.GetCnOrEnMenuId("history_index_id", menuId);
                int num5 = base.sm.GetCnOrEnMenuId("importance_index_id", menuId);
                for (int i = 0; i < subMenuList.Count; i++)
                {
                    info2 = (SysMenuInfo)subMenuList[i];
                    if (menuId == num3)
                    {
                        if ((((info2.Node_ID != num3) && (info2.Node_ID != num2)) && (info2.Node_ID != num4)) && (info2.Node_ID != num5))
                        {
                            builder.Append(module.GetSesc(info2.Node_ID, info2.Node_Name));
                        }
                    }
                    else if (info2.Node_ID != num2)
                    {
                        builder.Append(module.GetSesc(info2.Node_ID, info2.Node_Name));
                    }
                }
            }
            return builder.ToString();
        }

        public string GetListContent(int menuId, int contentId, int pageIndex)
        {
            GroupModule module = new GroupModule();
            return module.GetIndexContent(menuId, contentId, pageIndex);
        }

        private string GetReplacedContent(int menuId, int contentId, int pageIndex)
        {
            if (contentId > 0)
            {
                GroupModule module = new GroupModule();
                return module.GetIndexContent(menuId, contentId, pageIndex);
            }
            int cnOrEnSubRootId = base.sm.GetCnOrEnSubRootId(menuId);
            if (menuId == cnOrEnSubRootId)
            {
                return this.GetIndexContent(menuId, contentId, pageIndex);
            }
            return this.GetListContent(menuId, contentId, pageIndex);
        }

        protected override string ReplaceContent(string templateContent, string replacedContent, int menuId, int contentId, int pageIndex, string searchType, string searchKey)
        {
            string str = replacedContent;
            if (templateContent.IndexOf("#####content#####") > 0)
            {
                str = StringUtil.ReplaceStr(str, "#####content#####", this.GetReplacedContent(menuId, contentId, pageIndex));
            }
            return str;
        }
    }
}